package procilege.impl.eval;

import procilege.compute.ExprEvaluationTraveller;
import procilege.compute.PlaceType;
import procilege.compute.PlaceTypeMetadata;
import procilege.impl.ComputationalEntityMgr;
import procilege.lang.PredicateEntityProperty;

import com.google.inject.Inject;

@PlaceTypeMetadata(type = PredicateEntityProperty.class)
public class PredicateEntityPropertyEvalPlace implements
		PlaceType<ExprEvaluationTraveller> {

	@Inject
	private ComputationalEntityMgr cem;

	public void visit(ExprEvaluationTraveller tr, Object place) {

		PredicateEntityProperty expr = (PredicateEntityProperty) place;

		Object val;
		val = cem.getEntityProperty(expr.getEntity(), expr.getProperty());
		if (val == null)
			throw new IllegalStateException("no value");

		tr.setout(val);
		val = tr.getPreviousVisitResult();

		tr.result(val);
	}
}